$(document).ready(function () {
    tdzzsysxx.onload();
})

var tdzzsysxx = (function () {

    var init = function () {
    	layui.use('form', function(){
			  var form = layui.form
		});
    }

    return {
        onload : function () {
            init();
            tdzzsysxx.formTab();
            tdzzsysxx.tDtableData();
            tdzzsysxx.bdctableData();
            tdzzsysxx.zrtableData();
            tdzzsysxx.checkoutAll();
            tdzzsysxx.dateShow();
            tdzzsysxx.checkClick();
        },
 
         /*tab选项卡*/
        formTab:function(){
	       	$(".wxl_fcys_tab span").click(function(){
	       		$(this).addClass("active").siblings("span").removeClass("active");
				var n=$(this).index();
				$(".wxl_cztdysxx_con>.wxl_table_box").eq(n).show().siblings(".wxl_table_box").hide();
				
			})
        },
        checkClick:function(){
			$(document).on('click','.checkbox_label label',function(){
				$(this).toggleClass("active")
			})
		},
		/*新增一行空行*/
        add_row: function () {
            var t = $('#wxlCztdsy').DataTable();//添加行时先获取一次datatable
            t.row.add({
                "operation":'',
                "SYBH": '',
                "SYZL": '',
                "QSQSZYDX_DM": '请选择',//当添加layui的下拉框时，此处必须填值，不能为空，为空时下拉选项有bug，为符合大众需求，可以填‘请选择’
                "QSZYLB": '请选择',
                "CJJG": '',
                "SFJTWYJSPFMJYXPTZF": '请选择',
                "SFJTDETJSPFMJYXPTZF": '请选择',
                "JMQXQ1": '<form class="layui-form"><input id="'+idName1+'"  type="text" /></form>',//添加的起始日期标签
                "JMQXZ1": '<form class="layui-form"><input id="'+idName2+'"  type="text" /></form>',//添加的终止日期标签
                "JZSL1": '',
                "JZFD1": '',
                "JZED1": ''
            }).draw( false );           
            //设置动态行的input的样式
            $('#wxlCztdsy tbody tr').last().find('td').children('input').addClass('add_row');
            /*$('#wxlCztdsy tbody tr').last().find('.layui-input').addClass('add_row');
            $('#wxlCztdsy tbody tr').last().find('.layui-form').children('input').addClass('add_row');*/
        },
        add_tdsyxx:function(){
       		layui.use('layer', function() {
					var layer = layui.layer;
					layer.open({
						type: 1,
						id:'layer_open',
						skin: 'layui-layer-demo', //样式类名
						closeBtn: 1, //不显示关闭按钮
						anim: 2,
						title: '土地税源信息',
						area: ['70%', '300px'],
						shadeClose: true, //开启遮罩关闭
						content: $('.wxl_cztdysxx_tdsyxx_box').html()
					});
			});
        },
        add_bdcxmxx:function(){
       		layui.use('layer', function() {
					var layer = layui.layer;
					layer.open({
						type: 1,
						id:'layer_open',
						skin: 'layui-layer-demo', //样式类名
						closeBtn: 1, //不显示关闭按钮
						anim: 2,
						title: '不动产项目信息',
						area: ['70%', '300px'],
						shadeClose: true, //开启遮罩关闭
						content: $('.wxl_cztdysxx_bdcxmxx_box').html()
					});
			});
        },
       /*土地信息表格数据交互*/
        tDtableData: function() {
 		var data = [{
 				"landNum": "001",
 				"landContractNum": "333333",
 				"time": "2018-12-20 15:30"
 			},
 			{
 				"landNum": "001",
 				"landContractNum": "333333",
 				"time": "2018-12-20 15:30"
 			}
 		];
 		$('#wxlTdxx').DataTable({
 			"data": data,
 			"columnDefs": [
 				{
 					'targets': 0,
 					'className': 'dt-body-center',
 					'render': function(data, type, row) {
 						return '<input class="checkchild" type="checkbox"/>';
 					}
 				},
 				{
                        'targets': 1,
                        'className': '',
                        'render': function(data, type, full, meta) {
                            return '<input type="text" value="'+ data +'"/>';  //返回简单数据，此处的data能够根据数据的条数自动遍历并赋值给每一行
                        }
                    },{
                        'targets': 2,
                        'className': '',
                        'render': function(data, type, full, meta) {
                            return '<input type="text" value="'+ data +'"/>';  //返回简单数据，此处的data能够根据数据的条数自动遍历并赋值给每一行
                        }
                    },{
                        'targets': 3,
                        'className': '',
                        'render': function(data, type, full, meta) {
                            return '<input type="text" value="'+ data +'"/>';  //返回简单数据，此处的data能够根据数据的条数自动遍历并赋值给每一行
                        }
                    },
 			],
 			"columns": [
 			    {
 					"data": "btn"
 				},
 			    {
 					"data": "landNum"
 				},
 				{
 					"data": "landContractNum"
 				},
 				{
 					"data": "time"
 				}
 			],
 			"paging": false,
 			"info": false,
 			"lengthChange": false,
 			"searching": false
 		});
      },
     /*信息不动产表格数据交互*/
      bdctableData: function() {
 		var data = [{
 				"bdcNum": "001",
 				"bdcName": "不动产1"
 			},
 			{
 				"bdcNum": "002",
 				"bdcName": "不动产2"
 			}
 		];
 		$('#bdcxmxx').DataTable({
 			"data": data,
 			"columnDefs": [
 				{
 					'targets': 0,
 					'className': 'dt-body-center',
 					'render': function(data, type, row) {
 						return '<input class="checkchild" type="checkbox"/>';
 					}
 				},
 				{
                        'targets': 1,
                        'className': '',
                        'render': function(data, type, full, meta) {
                            return '<input type="text" value="'+ data +'"/>';  //返回简单数据，此处的data能够根据数据的条数自动遍历并赋值给每一行
                        }
                    },{
                        'targets': 2,
                        'className': '',
                        'render': function(data, type, full, meta) {
                            return '<input type="text" value="'+ data +'"/>';  //返回简单数据，此处的data能够根据数据的条数自动遍历并赋值给每一行
                        }
                    },
 			],
 			"columns": [
 			    {
 					"data": "btn"
 				},
 			    {
 					"data": "bdcNum"
 				},
 				{
 					"data": "bdcName"
 				}
 			],
 			"paging": false,
 			"info": false,
 			"lengthChange": false,
 			"searching": false
 		});
      },
       /*转让信息表格数据交互*/
      zrtableData: function() {
 		var data = [{
 				"assignmentCx": "001",
 				"assignLandArea": "33333",
 				"assignJzArea": "44444",
 				"assignContractDate": "2018-2-19"
 			},
 			{
 				"assignmentCx": "002",
 				"assignLandArea": "5555",
 				"assignJzArea": "33333",
 				"assignContractDate": "2018-2-19"
 			}
 		];
 		$('#wxlZr').DataTable({
 			"data": data,
 			"columnDefs": [
 				{
 					'targets': 0,
 					'className': 'dt-body-center',
 					'render': function(data, type, row) {
 						return '<input class="checkchild" type="checkbox"/>';
 					}
 				},{
                        'targets': 1,
                        'className': '',
                        'render': function(data, type, full, meta) {
                            return '<input type="text" value="'+ data +'"/>';  //返回简单数据，此处的data能够根据数据的条数自动遍历并赋值给每一行
                        }
                    },{
                        'targets': 2,
                        'className': '',
                        'render': function(data, type, full, meta) {
                            return '<input type="text" value="'+ data +'"/>';  //返回简单数据，此处的data能够根据数据的条数自动遍历并赋值给每一行
                        }
                    },{
                        'targets': 3,
                        'className': '',
                        'render': function(data, type, full, meta) {
                            return '<input type="text" value="'+ data +'"/>';  //返回简单数据，此处的data能够根据数据的条数自动遍历并赋值给每一行
                        }
                    },{
                        'targets': 4,
                        'className': '',
                        'render': function(data, type, full, meta) {
                            return '<input type="text" value="'+ data +'"/>';  //返回简单数据，此处的data能够根据数据的条数自动遍历并赋值给每一行
                        }
                    },
 			],
 			"columns": [
 			    {
 					"data": "btn"
 				},
 			    {
 					"data": "assignmentCx"
 				},
 				{
 					"data": "assignLandArea"
 				},
 				{
 					"data": "assignJzArea"
 				},
 				{
 					"data": "assignContractDate"
 				}
 			],
 			"paging": false,
 			"info": false,
 			"lengthChange": false,
 			"searching": false
 		});
      },
      /*table表格全选*/
     checkoutAll:function(){
         $('.checkall').on('click', function () {
               if (this.checked) {
                    $(this).attr('checked','checked')
                    $('.checkchild').each(function () {
                        this.checked = true;                        
                    });
                } else {
                    $(this).removeAttr('checked')
                    $('.checkchild').each(function () {
                        this.checked = false;
                    });
                }                 
        });   
        $('.checkchild').each(function () {
            $(this).click(function(){
            	var checkLen=$("tbody input[type='checkbox']").length;
				var checkSelect=$("tbody input[type='checkbox']:checked").length;
				if(checkLen==checkSelect){
					$(".checkall").prop("checked",true)
        		}else{
        			$(".checkall").prop("checked",false)
        		}
     		})
        })
    },
    
    /*日期显示*/
        dateShow:function(){
        	layui.use('laydate', function(){
			  var laydate = layui.laydate;
			  laydate.render({
				    elem: '#wxl_date1'
				    ,theme: 'molv'
			 });
			  laydate.render({
				    elem: '#wxl_date2'
				    ,theme: 'molv'
			 });
			})
        }
     }
})();
